package com.xiye.common.util;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.xiye.common.entity.Result;

import java.util.Map;

/**
 * @Package com.xiye.common.util
 * @Description 前后端交互数据标准
 * @Author 西野
 * @Date 2018-08-07
 * @Version V1.0
 */
public class ResultUtil {

    /* 
     * @Author 西野
     * @Date 2018-08-08 14:44:34
     * @Description 返回json字符串
     * @Param [b, code, message, map]
     * @Return java.lang.Object
     */  
    public static Object setRowbackResut_json(boolean b, Integer code, String message, Map<String, Object> map) {
        Result result = new Result();
        result.setSuccess(b);
        result.setMessage(message);
        result.setCode(code);
        result.setResult(map);
        String json = JSONObject.toJSONString(result, SerializerFeature.WriteMapNullValue, SerializerFeature.WriteNullNumberAsZero, SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullBooleanAsFalse, SerializerFeature.DisableCircularReferenceDetect);
        return json;
    }

    /* 
     * @Author 西野
     * @Date 2018-08-08 14:44:37
     * @Description 返回实体，用以配合swagger2展示数据显示
     * @Param [b, code, message, map]
     * @Return com.xiye.common.entity.Result
     */  
    public static Result setRowbackResut_entity(boolean b, Integer code, String message, Map<String, Object> map) {
        Result result = new Result();
        result.setSuccess(b);
        result.setMessage(message);
        result.setCode(code);
        result.setResult(map);
        return result;
    }
}
